TEST_CASE_PATH=~/standalone/arkcompiler/ets_runtime/test/aottest
RUN_SCRIPT=~/test/js_test/baseline/run.sh

cd $TEST_CASE_PATH
TOTAL_CASES=0
PASS_CASES=0
FAIL_CASES=0

rm -f fail_cases.log
rm -f pass_cases.log
rm -f other_cases.log

execute_cases() {
           echo ------------------ internal caseName: $innerName ------------------
	   let TOTAL_CASES++
           # run current case
           $RUN_SCRIPT $1
           # verify current case
           if [ $? -eq 0 ]
           then
               let PASS_CASES++
               echo "pass case: $1" >> $TEST_CASE_PATH/pass_cases.log
           elif [ $? -eq -2 ]
           then
               let FAIL_CASES++
               echo "having different result: $1" >> $TEST_CASE_PATH/fail_cases.log
           else
               let FAIL_CASES++
               echo "fail case: $1" >> $TEST_CASE_PATH/fail_cases.log
           fi
           rm -f output*.txt
           rm -f expect.txt
}

# run all cases and verify result
for case in `ls`
do
    # skip time-consuming cases
    #if [ "$case" == "aot_multi_constantpool_test" ] || [ "$case" == "continue_from_finally" ] || [ "$case" == "generatorcontinuefinally" ] || [ "$case" == "typearray_load_store" ]
    #then
    #    continue
    #fi

    cd $TEST_CASE_PATH/$case
    echo ======================= external caseName: $case =======================
    echo ">>>> execute cases in $case :"

    allCases=`find . -name *.ts`
    for inner in $allCases
    do
       tmp=${inner%/*}
       innerPath=${tmp#*/}

       if [ "$innerPath" != "." ]
       then
           echo cd $TEST_CASE_PATH/$case/$innerPath
           cd $TEST_CASE_PATH/$case/$innerPath
           innerName=`ls *.ts`
           execute_cases $innerName
       else
           innerName=`ls *.ts`
           execute_cases $innerName
       fi
     done
done

# output infos
echo -e '\n'
echo "total cases: $TOTAL_CASES" 
echo "pass cases: $PASS_CASES"
echo "fail cases: $FAIL_CASES"
